var http_request = null;

function init() {
	document.body.style.width="50px";
	background.style.width = "31px";
	background.style.height = "31px";
	background.src = "url(images/bg.png)";
	updateTemp();
}

function updateTemp() {
	try {
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
		http_request.open("GET", "http://www.eol.ucar.edu/cgi-bin/weather.cgi?site=fl&period=5-minute&fields=tdry&fields=rh&fields=cpres0&fields=wspd&fields=wdir&fields=raina&units=english", false);		
		http_request.send();
		if (http_request.status == 200) {
			parseData();
		}
	} catch (e) {

	}

	self.setTimeout( "updateTemp()", 1000*60*5 );
}

function parseData() {
    var tempf = 0;
	var response = http_request.responseText;
    var index = response.indexOf("<th>Temperature</th>");
    var temp = response.substring(index+62, index+70);
	

    if(temp.indexOf(".") == 1) {
      tempf = temp.substring(2,3);
      temp = temp.substring(0, 1);   
    }  else if(temp.indexOf(".") == 2) {
      tempf = temp.substring(3,4);   
      temp = temp.substring(0, 2);
    }  else if(temp.indexOf(".") == 3) {
      tempf = temp.substring(4,5);
      temp = temp.substring(0, 3);   
    }

    var icon = "images/" + temp + ".ico";
	symbolImage.src= icon;
    symbolImage.alt="Boulder: " + temp + "." + tempf + " degrees";
}
